package cn.yeziji.forum.dao.iquery;

import cn.org.atool.fluent.mybatis.base.crud.JoinBuilder;
import cn.org.atool.fluent.mybatis.segment.JoinQuery;
import cn.yeziji.forum.wrapper.ForumCommentQuery;
import cn.yeziji.forum.wrapper.ForumUserCommentQuery;

/**
 * 评论查询条件构造器
 *
 * @author gzkemays
 * @since 2022/3/28 20:47
 */
public class CommentQuery {
  /**
   * 获取文章评论
   *
   * @param detailId 文章id
   * @param userId 用户 id
   * @return 连接表查询构造器
   */
  public static JoinQuery getDetailCommentListMapsQuery(Integer detailId, Integer userId) {
    return JoinBuilder.from(
            new ForumCommentQuery()
                .selectAll()
                .where
                .detailId()
                .eq(detailId)
                .end()
                .orderBy
                .createTime()
                .desc()
                .end())
        .leftJoin(new ForumUserCommentQuery().select.toGood().end())
        .on(l -> l.where.id(), r -> r.where.commentId())
        .onRight(q -> q.where.userId().eq(userId))
        .endJoin()
        .build();
  }
}
